package com.springboot2.service.Impl;

import com.springboot2.entity.Goods;
import com.springboot2.mapper.GoodsMapper;
import com.springboot2.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GoodServiceImpl implements GoodsService {

    @Resource
    private GoodsMapper goodsMapper;

    @Override
    public void add(Goods goods) {
        goodsMapper.add(goods);
    }

    @Override
    public void del(int id) {
        goodsMapper.del(id);
    }

    @Override
    public void update(Goods goods) {
        goodsMapper.update(goods);
    }

    @Override
    public Goods findById(int id) {
        return goodsMapper.findById(id);
    }

    @Override
    public List<Goods> findByPage(int pageNo, int pageSize) {
        Map<String,Integer> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);

        return goodsMapper.findByPage(map);
    }

    @Override
    public int count() {
        return goodsMapper.count();
    }

    @Override
    public List<Goods> findByPageParams(int pageNo, int pageSize, String title) {
        Map<String,Object> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("title",title+"%");
        return goodsMapper.findByPageParams(map);
    }

    @Override
    public int countParams() {
        return goodsMapper.countParams();
    }
}
